package morefun.demo

import org.apache.spark.{SparkConf, SparkContext}

object AccumulatorVariable {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("AccumulatorVariable ").setMaster("local")
    val sc = new SparkContext(conf)
    val numList = sc.parallelize(Array(1,2,3,4,5,6,7,8,9,10))

    var sum = sc.accumulator(0)
    numList.foreach( num => sum.add(num))

    println(sum.value)
  }
}
